#!/bin/bash
#
# Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

# Install grub to disk. Only used in x86 based platforms

if ! is_loongson; then
  return 0
fi

config_item() {
  if [ -f /etc/default/grub ]; then
    . /etc/default/grub || return
  fi
  eval echo "\$$1"
}

GRUB_TIMEOUT=$(installer_get "grub_timeout")
GRUB_TIMEOUT=${GRUB_TIMEOUT:-1}

cat >> /etc/default/grub << EOF
# Generated by deepin-installer
GRUB_BACKGROUND="/boot/grub/themes/deepin/background.png"
GRUB_CMDLINE_LINUX_DEFAULT="splash quiet console=tty loglevel=0"
GRUB_DEFAULT=0
GRUB_DISTRIBUTOR="\`/usr/bin/lsb_release -d -s 2>/dev/null || echo Uos\`"
GRUB_THEME="/boot/grub/themes/deepin/theme.txt"
GRUB_TIMEOUT=${GRUB_TIMEOUT}
GRUB_GFXMODE=${DI_CUR_RESOLUTION}
EOF

# update grub config
update_grub_local
